package main

import (
	"log"
	"time"
	"yundian/internel/pkg/dbs"
	"yundian/internel/pkg/dingo"
	"yundian/internel/pkg/wechatpay"
)

func resolveTime(seconds int) (hour, minute, second int) {
	var day = seconds / (24 * 3600)
	hour = (seconds - day * 3600 * 24) / 3600
	minute = (seconds - day * 24 * 3600 - hour * 3600) / 60
	second = seconds - day * 24 * 3600 - hour * 3600 - minute * 60
	return
}

func main()  {
	dingo.InitViper("./configs/adm.yaml")
	dbs.NewMysqlComponent().Step()

	// c0fa9b7e25b0ae49c32e97903526004ce4b0e851a3940f5f921fd135a5642418
	//log.Println(utils.EncryptPassword("chinaman@2021")) // 296298cf4eeb387584947eafe230bea0d335a8960e41015b7d8808a23d290246
	//log.Println(utils.EncryptPassword("Zhongman@cnman2021"))
	//7a5604a57446454a9dc0b94e6e3e23e5b80fb4b8b531a7b6168625fb247e44a0

	//9a583f0e862d4c8de2a190b1421ab3d3d67042fef168e3713ccec1307d85c5fe
	//log.Println(utils.EncryptPassword("ZhongmanSuChong@2021~"))

	// c0fa9b7e25b0ae49c32e97903526004ce4b0e851a3940f5f921fd135a5642418
	//log.Println(utils.EncryptPassword("123456"))

	// 2715656923ecdf92dac7187a721efc52ce1d62afa1f02d0c804bb947b7a571ae
	//log.Println(utils.EncryptPassword("cnman20200927"))

	// c86877d54f2e8cd40dc5cfd3bfaf79dee0aefc28cdc4708b555bbffb6f0ede53
	//log.Println(utils.EncryptPassword("zmjsfw@2021"))

	//t := 1618839173
	//log.Println(wechatpay.FormatIntTime(int64(t)))


	//t := 489741
	//log.Println(resolveTime(t))
	//time.Duration(t)*time.Second
	//log.Println(time.Now().Add(3600 * time.Second).Format("15:04:05"))
	//s := "831YD00003"
	//s = string([]byte(s)[:5])
	//fmt.Println(s) //得到 "abc"

	//deviceSns := strings.Split(s, "YD")
	//log.Println(len(s))
	//log.Println(deviceSns[0])
	//log.Println(deviceSns[1])
	//log.Println(deviceSns[2])

	//lastProfit := decimal.NewFromInt(0)
	//curruserProfit := decimal.NewFromInt(int64(70))
	//sett := decimal.NewFromInt(2)
	//log.Println(curruserProfit.Sub(lastProfit).Mul(sett))
	//money := curruserProfit.Sub(lastProfit).Mul(sett).Div(decimal.NewFromInt(100))
	//log.Println("分红金额为", money)


	//var startTime, endTime int64
	//startTime = 1612416936
	//endTime = 1612416943
	//end := decimal.NewFromInt(endTime).Sub(decimal.NewFromInt(startTime))
	//
	//price, err := decimal.NewFromString("136.02")
	//if err != nil {
	//	panic(err)
	//}
	//
	//quantity := decimal.NewFromInt(3)
	//
	//fee, _ := decimal.NewFromString(".035")
	//taxRate, _ := decimal.NewFromString(".08875")
	//
	//subtotal := price.Mul(quantity)
	//
	//preTax := subtotal.Mul(fee.Add(decimal.NewFromFloat(1)))
	//
	//total := preTax.Mul(taxRate.Add(decimal.NewFromFloat(1)))
	//
	//fmt.Println("Subtotal:", subtotal)                      // Subtotal: 408.06
	//fmt.Println("Pre-tax:", preTax)                         // Pre-tax: 422.3421
	//fmt.Println("Taxes:", total.Sub(preTax))                // Taxes: 37.482861375
	//fmt.Println("Total:", total)                            // Total: 459.824961375
	//fmt.Println("Tax rate:", total.Sub(preTax).Div(preTax)) // Tax rate: 0.08875

	//var a,b int
	//a = 805
	//b = 4
	//log.Println(a/b)


	//fmt.Println(time.Now().Format("2006-01-02"))
	//str := "2020-12-15 23:59:58"
	//
	//t := wechatpay.StrTimeToInt(str)
	//
	//fmt.Println(t)
	//
	//var ti int64
	//1609084800000 1609689599999
	//6911020800,6942556799
	//1609496957,1609669757
	//ti = 1609669757
	//
	//b,_ := convt(ti)
	//
	//fmt.Println(string(b))

	//l, _ := time.LoadLocation("Asia/Shanghai")
	//startTime,_ := time.ParseInLocation("2006-01-02 15:04:05", "2021-11-01 00:00:00", l)
	//endTime,_ := time.ParseInLocation("2006-01-02 15:04:05", "2021-11-01 23:59:59", l)
	//log.Println(startTime.Unix(), endTime.Unix())
	//
	//getLastMonthStartEnd()

	n := time.Now()
	//d := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
	d := time.Date(n.Year(), n.Month(), n.Day(), 07, 07, 0, 0, wechatpay.BeijingLocation).Format("2006-01-02 15:04:05")
	if n.Hour() > 7 && n.Hour() < 16 {
		log.Println(123)
	} else {
		log.Println(321)
	}
	log.Println(n.Hour(), d)


	//var BeijingLocation = time.FixedZone("Asia/Shanghai", 8*60*60)
	//now := time.Now()
	//lastMonthFirstDay := now.AddDate(0, 0, -31)
	//log.Println(lastMonthFirstDay.Format("2006-01-02 15:04:05"))

	//datas := helper.WeekByDate(time.Now().AddDate(0,0,-1))
	//fmt.Println(helper.WeekByDate(time.Now().AddDate(0,0,-1)))
	//fmt.Println(helper.WeekByDate(time.Now().AddDate(0,0,-2)))
	//fmt.Println(helper.WeekByDate(time.Now().AddDate(0,0,-3)))
	//fmt.Println(helper.WeekByDate(time.Now().AddDate(0,0,-4)))
	//fmt.Println(helper.WeekByDate(time.Now().AddDate(0,0,-5)))
	//fmt.Println(helper.WeekByDate(time.Now().AddDate(0,0,-6)))
	//fmt.Println(helper.WeekByDate(time.Now().AddDate(0,0,-7)))
	//for _, d := range datas {
	//	fmt.Println(d)
	//}
	//c,_ := convt(1610757987000)
	//fmt.Println(string(c))
}


const timeFormart = "2006-01-02 15:04:05"
func convt(t int64) ([]byte, error) {
	b := make([]byte, 0, len(timeFormart) + 2)
	b = append(b, '"')
	b = time.Unix(t, 0).AppendFormat(b, timeFormart)
	//b = time.Time(t).AppendFormat(b, timeFormart)
	b = append(b, '"')
	return b, nil
}


func getLastMonthStartEnd() {
	now := time.Now()
	lastMonthFirstDay := now.AddDate(0, -1, -now.Day()+1)
	lastMonthStart := time.Date(lastMonthFirstDay.Year(), lastMonthFirstDay.Month(), lastMonthFirstDay.Day(), 0, 0, 0, 0, now.Location())
	lastMonthEndDay := lastMonthFirstDay.AddDate(0, 1, -1)
	lastMonthEnd := time.Date(lastMonthEndDay.Year(), lastMonthEndDay.Month(), lastMonthEndDay.Day(), 23, 59, 59, 0, now.Location())
	log.Println(lastMonthStart.Format("2006-01-02 15:04:05"), lastMonthEnd.Format("2006-01-02 15:04:05"))
}
